package me.helllp.bootman.back.config.shiro;

import org.apache.shiro.authc.AuthenticationToken;
import org.apache.shiro.subject.Subject;
import org.apache.shiro.subject.SubjectContext;
import org.apache.shiro.web.mgt.DefaultWebSubjectFactory;

/**
 * 自定义工厂,JWT token的情况下不创建Session
 * 
 * @author 林晓明
 *
 */
public class BootmanSubjectFactory extends DefaultWebSubjectFactory {
    @Override
    public Subject createSubject(SubjectContext context) {
        AuthenticationToken token = context.getAuthenticationToken();
        
        if((token instanceof JwtToken)){
            // 当token为JwtToken时， 不创建 session 
            context.setSessionCreationEnabled(false);
        }
        return super.createSubject(context);
    }
}
